<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglib.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>新增版本</title>
   	<link rel="stylesheet" href="${ctx}/static/css/Master.css"/>
	<link rel="stylesheet" href="${ctx}/static/css/lq.datetimepick.css"/>
	<link href="${ctx}/static/css/default.css" type="text/css" rel="stylesheet"/>
	<link href="${ctx}/static/css/uploadify.css" type="text/css" rel="stylesheet"/>
	<script type="text/javascript" src="${ctx}/static/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/simpletooltip.min.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/jsScroller.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/selectUi.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/lq.datetimepick.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/orgCommon.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/layer.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/jquery.uploadify.v2.0.3.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/swfobject.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/jquery.form.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/jquery.validate.min.js"></script>
	<link href="${ctx}/static/css/validation.css" type="text/css" rel="stylesheet"/>
	<script type="text/javascript" src="${ctx}/static/js/messages_cn.js"></script>
	<script src="${ctx}/static/plugins/My97DatePicker/WdatePicker.js"></script>
	<style type="text/css">
		#content{ width:100%; background:#525252; position:absolute; left:0; top:0px; bottom:1px;}
		#main_right {
		  margin: 0px;
		  height: 100%;
		  overflow: auto;
		  border-top: 1px solid #717171;
		  background: #fff;
		}
		.wrapper input{
		  height: 30px !important
		}
	</style>
	<script type="text/javascript">
	$(document).ready(function()
	{
	    $("#uploadify1").uploadify(uploader('${ctx }/file/uploadFile.do?type=7','imgDiv1'));
	    
	    $("#verUpWay").change(function(){
	    	var val = $(this).val();
			if(val == 1)
			{
				$("#file").attr("style","display:none;");
			}
			else
			{
				$("#file").removeAttr("style");
			}
		});
	});
	
	function uploader(url,imgDiv)
	{
		var t = {
		        'uploader': '${ctx}/static/images/uploadify.swf',
		        'script': url,
		        'cancelImg': '${ctx}/static/images/cancel.png',
		        'queueID' : 'fileQueue', // 文件队列的ID，该ID与存放文件队列的div的ID一致
				'queueSizeLimit' : 1, // 当允许多文件生成时，设置选择文件的个数，【默认值：999】
				'fileDesc' : 'apk文件', // 用来设置选择文件对话框中的提示文本'jpg、gif、jpeg、png文件'
				'fileExt' : '*.apk', // 设置可以选择的文件的类型'*.jpg;*.gif;*.png;*.jpeg'
				'auto' : true, // 设置为true当选择文件后就直接上传了，为false需要点击上传按钮才上传
				'multi' : false, // 设置为true时可以上传多个文件
				'width' : 140, // 宽度
				'simUploadLimit' : 1, // 允许同时上传的个数 【默认值：1】
				'sizeLimit' : 2048000, // 上传文件的大小限制 【单位byte】
				'buttonText' : '上传文件', // 浏览按钮的文本，默认值：BROWSE
				'displayData' : 'percentage',// 上传队列显示的数据类型【percentage：百分比，speed：上传速度】
				'onComplete' : function(evt, queueID, fileObj, response, data) {
					var newFile = JSON.parse(response)[0];
					$("#verFilename").val(newFile.filOriName);
					$("#verDownurl").val("${fUrl }"+newFile.filSerPath);
					var length = filelist.push(newFile);// 将一个或多个新元素添加到数组结尾，并返回数组新长度
				},
				'onError' : function(event, queueID, fileObj, errorObj) {
					if (errorObj.type === "File Size") {
						//alert("上传文件大小限制为" + parseInt(errorObj.info/1024) + "KB");
						top.layer.msg("上传文件大小限制为" + parseInt(errorObj.info/1024) + "KB", 2,{type: 8}, function(){});
						$("#headImg").uploadifyClearQueue();
					}
				}
			};
		return t;
	}
	
	function removeImg(code){
		
		//删除新增的文件
		$.ajax({    
		    url:"${ctx }/file/deleteFile.do",    
		    data:{"path":$(code).attr("url")},    
		    type:"post",    
		    cache:false,    
		    dataType:"json",
		    async:true, //默认为true 异步    
		    success:function(data) {    
		     },    
		     error : function() {    
		     }    
		});
		
		for ( var i = 0; i < filelist.length; i++) {
			if(filelist[i].filSerPath == $(code).attr("url")){
				var oldData = filelist.splice(i,1);
			}
		}
		$(code).parent().remove();
	}
	
	function save()
	{
		if(!$("#verForm").valid())
		{
			return;
		}
		var data = $("#verForm").serializeJson();
		$.ajax({
			url:"${ctx }/appManager/saveAppVersion.do",    
		    data:data,    
		    type:"POST",    
		    cache:false,    
		    dataType:"json",
		    async:false, //默认为true 异步 
		    success:function(data) {
		    	top.layer.alert("操作成功",function(){
		    		window.location.href = "${ctx}/appManager/findVersionList.do";
		    	});
		    } 
		});
	}
	</script>
  </head>
  
  <body>
  	<form id="verForm">
	<div class="wrapper">
		<section id="content" >
			<section id="main_right">
				<section class="boxRight">
					<div class="OrgTit">新增</div>
					<div class="context">
						<div class="add_firstmenu">
							<dl>
								<dt>
									操作平台
								</dt>
								<dd>
									 <select id="verOs" name="verOs">
								     <c:forEach items="${diy:getDicList('SET_VERSION')}" var="dic">
								     <option value="${dic.code}" checked>${dic.content}</option>
								     </c:forEach>
								     </select>
								</dd>
							</dl>
							<dl>
								<dt>
									版本值
								</dt>
								<dd><input id="verVersion" name="verVersion" type="text" class="w1 "/></dd>
							</dl>
							<dl>
								<dt>
									<span class="im">*</span>版本号
								</dt>
								<dd>
									<input id="verVersionVal" name="verVersionVal" type="text" class="required digits w1"/>
								</dd>
							</dl>
							<dl>
								<dt>
									<span class="im">*</span>上传方式
								</dt>
								<dd>
									 <select id="verUpWay" name="verUpWay" class="required">
								     <c:forEach items="${diy:getDicList('UP_WAY')}" var="dic">
								     <option value="${dic.code}" checked>${dic.content}</option>
								     </c:forEach>
								     </select>
								</dd>
							</dl>
							<dl>
								<dt></dt>
								<dd>
									<div class="ddpic" id="imgDiv1">
										<input type="text" id="verDownurl" name="verDownurl" />
										<input type="hidden" id="verFilename" name="verFilename" />
									</div>
									<div class="ddbtn prlink" id="file"><input type="file" name="uploadify1" id="uploadify1" class="required" /></div>
								</dd>
							</dl>
							<dl>
								<dt>
									<span class="im">*</span>发布时间
								</dt>
								<dd>
									<input id="verReleaseTime" name="verReleaseTime" type="text" class="required Wdate w1" onclick="WdatePicker()"/>
								</dd>
							</dl>
							<dl>
								<dt>
									<span class="im">*</span>更新说明
								</dt>
								<dd>
									<div class="textareaBox">
										<textarea id="verDepict" name="verDepict" class="required" ></textarea>
									</div>
								</dd>
							</dl>
							<dl>
								<dt>
									<span class="im">*</span>强制更新
								</dt>
								<dd>
									<div class="labelautybox labelautybox3">
										<input type="radio" name="verCoerceUpdate" id="r1" value="0" checked>否
										<input type="radio" name="verCoerceUpdate" id="r2" value="1" >是
									</div>
								</dd>
							</dl>
							<div class="combtn"><a href="javascript:save();">确定</a><a href="javascript:void(0);"onclick="history.back();">返回</a></div>
						</div>
					</div>
			</section>
			</section>
		<!--/左边-->
		</section>
	</div>
	</form>
  </body>
</html>
